package com.augurit.wf.jbpmex.task.multitask.completerule;

import java.util.List;

import org.jbpm.api.history.HistoryTask;
import org.jbpm.pvm.internal.history.model.HistoryTaskImpl;
import org.jbpm.pvm.internal.task.TaskImpl;

import com.augurit.common.base.form.ResultForm;
import com.augurit.wf.jbpmex.task.multitask.completerule.base.BaseCompleteRule;

public class ByAllRule extends BaseCompleteRule {

	public void init(TaskImpl curTask, TaskImpl superTask, List<HistoryTaskImpl> hisChildTasks) {
		super.initParams(curTask, superTask, hisChildTasks);
	}
	
	@Override
	public boolean isEnd() {
		if(hisChildTasks != null && hisChildTasks.size() > 0){
			for(int i=0; i<hisChildTasks.size(); i++){
				HistoryTaskImpl hisTask = (HistoryTaskImpl)hisChildTasks.get(i);
				if(!hisTask.getState().equals(HistoryTask.STATE_COMPLETED))
					return false;
			}
		}
		
		return true;
	}
	
	@Override
	public ResultForm validate(String[] userKeys) {
		ResultForm result = new ResultForm(true);
		return result;
	}
}
